Using PowerShell class to invoke a "[namespace.class]::method" style command

Posted by Marco on Stack Overflow See other posts from Stack Overflow or by Marco
Published on 2010-03-27T12:24:07Z Indexed on 2010/03/27 20:33 UTC
Read the original article Hit count: 221

Filed under:
|

Hello, I created a powershell object via .net to invoke commands. When I invoke normal commands like 'Get-Process' I had no problems:

ps.AddCommand("Get-Process").AddParameter(...).Invoke()

but I'm not able to invoke a .net method with the syntax "[namespace.class]::method", just to make an example to invoke [System.IO.File]::Exists("c:\boo.txt").

I tried with

ps.AddCommand("[System.IO.File]::Exists(\"c:\\boo.txt\")").Invoke()

ps.AddCommand("[System.IO.File]::Exists").AddArgument("c:\\boo.txt").Invoke()

and some others. It always throws an exception which says that the command specified is not recognized.

There is a way to invoke that type of command? Thanks

© Stack Overflow or respective owner

Related posts about .NET

Related posts about powershell